package cn.itsource.basic.base.controller;

import cn.itsource.basic.base.service.ILoginService;
import cn.itsource.basic.utils.AjaxResult;
import cn.itsource.org.domain.dto.LoginDto;
import cn.itsource.org.domain.dto.WxParamDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private ILoginService loginService;

    @PostMapping("/adminlogin")
    public AjaxResult adminLogin(@RequestBody LoginDto dto){
        try {
            return AjaxResult.me().setResultObj(loginService.adminLogin(dto));
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("服务器忙，请稍后重试");
        }
    }

    @PostMapping("/wechat")
    public AjaxResult webchat(@RequestBody Map<String,String> map){
        try {
            //返回两种情况，有账号 登录成功 map（token,logininfo）
            //没有账号 ?accesstoke=asdfasdf&openid=asd;lkjfla;ksdj
            return loginService.webchat(map);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("服务器忙，请稍后重试");
        }
    }


    @PostMapping("/wechat/binder")
    public AjaxResult binder(@RequestBody WxParamDto paramDto){
        try {
            return loginService.binder(paramDto);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("服务器忙，请稍后重试");
        }
    }

}
